package com.lw.main.word;

import com.lw.util.GameUtil;
import lombok.Data;

import java.awt.*;

/**
 * 游戏最高分数记录
 */
@Data
public class GameRecord {

    private int nowRecord;//当前分数
    private int maxRecord;//最高纪录
    private boolean changed = false;//最高记录是否改变了

    public GameRecord(){
        this.changed = false;
        this.maxRecord = GameUtil.getRecord();
    }

    /**
     * 比较并记录最高记录
     * @param compareRecord
     */
    public void changeMaxRecord(long compareRecord){
        this.nowRecord = (int)compareRecord;
        if (nowRecord > this.maxRecord) {
            this.maxRecord = nowRecord;
            this.changed = true;
        }
    }

    /**
     * 数据改变才记录最高记录
     */
    public void saveRecord(){
        if(changed) GameUtil.setRecord(String.valueOf(this.maxRecord));
    }

    public void draw(Graphics g,long compareRecord){
        this.changeMaxRecord(compareRecord);
        g.drawString("最高纪录：" + maxRecord, 200, 50);
    }
}
